﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Futaba.SBus.Telemetry
{
	/// <summary>
	/// Implementors can process telemetry data from the S.BUS stream
	/// </summary>
	public interface ITelemetryParser : ISbusParser<ISlot>
	{

		/// <summary>
		/// Returns the amount of Sequence-Errors which occured
		/// </summary>
		/// <remarks>
		/// Sequence information is only returned, when reading from the TX's port, as the TX
		/// will also return telemetry data, if it is currently not receiving telemetry from the model
		/// </remarks>
		/// <seealso cref="ISbusParser{ISlot}.Reset"/>
		int SequenceErrors { get; }

		/// <summary>
		/// Set by the <see cref="ISbusParsingService"/>, if channel-data is also available
		/// </summary>
		/// <remarks>
		/// When reading from the TX's data-port, telemetry data is sent a bit differently.
		/// The sequence byte is only sent from the TX, and the TX will also stream telemetry data, 
		/// even if it's not receiving newer values from the RX. It will also send ZEROs for many
		/// slots every second packet (probably because it doesn't receive telemetry as fast as it
		/// streams it to the data port)
		/// </remarks>
		bool TxTelemetryPassthroughMode { get; set; }

		/// <summary>
		/// The value parser used to extract the actual value from the payload of the slot.
		/// If not set, then <see cref="SlotValueParser.DefaultInstance"/> is used
		/// </summary>
		SlotValueParser ValueParser { get; set; }

		/// <summary>
		/// Raised if a telemetry-packet has been received with an unexpected sequence
		/// </summary>
		/// <seealso cref="SequenceErrors"/>
		event EventHandler OutOfSequence;

		/// <summary>
		/// Raised when values for a slot are received, but the slot is not in the 
		/// <see cref="ISbusParser{ISlot}.ItemsCollection"/>
		/// </summary>
		event EventHandler<SlotIdType> UnknownSlotReceived;

	}
}
